const router = require("koa-router")();
const Help = require('../help.js');
router.prefix("/api");
router.get('/add_convert',async (ctx, next)=>{
  let {src,savedir,inbands,outbands,do_ovr,do_cog,do_upload,priority}=Help.Get_Pamars(ctx)
  if(!src){
    Help.Resolve(ctx,true,false,'参数src是必须的') 
    return
  }
  if(priority>50){
    priority=priority-0
  }
  else{
    priority=50
  }
  let add_convert_ob={
    src,
    savedir,
    inbands,
    outbands,
    do_ovr:do_ovr==1?true:false,
    do_cog:do_cog==1?true:false,
    do_upload:do_upload==1?true:false,
  }
  await Help.add_rabbitmq(add_convert_ob,"tif_convert",priority)
  return Help.Resolve(ctx,true,true,'');
});
router.get('/add_ovr',async (ctx, next)=>{
  let {src,do_cog,do_upload,priority}=Help.Get_Pamars(ctx)
  if(!src){
    Help.Resolve(ctx,true,false,'参数src是必须的') 
    return
  } 
  if(priority>50){
    priority=priority-0
  }
  else{
    priority=50
  }
  let add_ovr_ob={
    src,
    do_ovr:true,
    do_cog:do_cog==1?true:false,
    do_upload:do_upload==1?true:false,
  }
  await Help.add_rabbitmq(add_ovr_ob,"tif_ovr",priority)
  return Help.Resolve(ctx,true,true,'');
});
router.get('/add_cog',async (ctx, next)=>{
  let {src,savedir,do_upload,priority}=Help.Get_Pamars(ctx)
  if(!src){
    Help.Resolve(ctx,true,false,'参数src是必须的') 
    return
  } 
  if(priority>50){
    priority=priority-0
  }
  else{
    priority=50
  }
  let add_cog_ob={
    src,
    savedir,
    do_cog:true,
    do_upload:do_upload==1?true:false,
  }
  await Help.add_rabbitmq(add_cog_ob,"tif_cog",priority)
  return Help.Resolve(ctx,true,true,'');
});
module.exports = router;